package com.doge.walknovel.business.novel

import com.doge.walknovel.core.account.AccountHelper.self
import com.doge.walknovel.utils.*
import java.io.*

object NovelChapterPosHelper {
    private val readChaptersDir: File get() {
        return File(appContext.externalCacheDir, "novelChaptersPos${self.memberId}").apply {
            if (!exists()) mkdirs()
        }
    }

    fun saveCache(key: Int, data: Int) = runOnIO {
        val file = File(readChaptersDir, key.toString())
        FileUtils.write(file, data.toString())
    }

    fun loadCache(key: Int): Int? {
        // require(!isMainThread())
        val file = File(readChaptersDir, key.toString())
        return FileUtils.read(file)?.toIntOrNull()
    }
}